import subprocess
import os
import re
import time
from tools import *

LOG = getlogger(__name__)


def main(regx, user=None, pidfile=None):
    pids = getprocess(regx, user, pidfile)
    if len(pids) > 0:
        for pid in pids:
            if not stop_proc(pid, 5):
                raise Exception("Exception when stop")
        return "OK"
    else:
        return "NOCHANGE"
